<?php
class km_cabang_model extends MY_Model {
	var $model = 'km_cabang';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	cabang_id, cabang_kode, cabang_nama, cabang_npwp, cabang_nopkp, cabang_tglpkp, cabang_alamat, cabang_telp, cabang_fax, cabang_tipe
					FROM	km_cabang 
					WHERE	(UPPER(cabang_kode) LIKE '%".strtoupper(post('keyword'))."%' OR 
							UPPER(cabang_nama) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'cabang_nama' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('km_cabang', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('km_cabang', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_roleid){
		$result = $this->db->get_where('km_cabang', array('cabang_kode' => $as_roleid));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_roleid)
	{
		$result = $this->db->get_where('km_cabang', array('cabang_kode' => $as_roleid));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			
			$this->db->delete('km_cabang', array('cabang_kode' => $arr_rule['cabang_kode']));
			return '';
			
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>